
package com.huaweicloud.saaslanding.install.properties;

import static com.huaweicloud.saaslanding.install.constant.ModelConstant.SKYWALKING_PREFIX;

import com.huaweicloud.saaslanding.basic.utils.CheckNullUtil;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

/**
 * 功能描述
 *
 * @since 2022-11-02
 */
@EqualsAndHashCode
@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
@Validated
@ConfigurationProperties(prefix = SKYWALKING_PREFIX)
public class Skywalking {

    /**
     * 是否启用skywalking服务
     */
    @NotNull
    private boolean enabled;

    /**
     * 服务地址
     */
    private String server;

    /**
     * 前端上报服务地址(端口不同)
     */
    private String uiReportHost;

    /**
     * 请求地址
     */
    private String url;

    public String getServer() {
        if (enabled && CheckNullUtil.isNotNull(server)) {
            return server;
        } else {
            throw new IllegalArgumentException("未启用skywalking或未配置server名称(server)");
        }
    }

    public String getUiServer() {
        if (enabled && CheckNullUtil.isNotNull(uiReportHost)) {
            return uiReportHost;
        } else {
            throw new IllegalArgumentException("未启用skywalking或未配置uiServer名称(uiReportHost)");
        }
    }

    public String getUrl() {
        if (enabled && CheckNullUtil.isNotNull(url)) {
            return url;
        } else {
            throw new IllegalArgumentException("未启用skywalking或未配置url地址(url)");
        }
    }
}
